<template>
  <header>
    <div class="l-content">
      <el-button icon="el-icon-menu" size="mini" @click="clickCollapse"></el-button>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="selectedMenu.path" v-if="selectedMenu">
          {{ selectedMenu.label }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown trigger="click" size="mini">
        <span class="el-dropdown-link"><img :src="userImg" class="user" /></span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item icon="el-icon-user">个人中心</el-dropdown-item>
          <el-dropdown-item icon="el-icon-login-out" @click.native="logOut">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </header>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      // 注意点：使用图片这种静态资源的时候需要使用require方法引用，把他作为一个模块来处理而不是作为一个字符串
      userImg: require('../assets/images/user.png'),
    }
  },
  computed: {
    ...mapState({
      selectedMenu: (state) => state.tab.currentMenu,
    }),
  },
  methods: {
    clickCollapse() {
      this.$store.commit('changeCollapse')
    },
    logOut() {
      // 退出操作要做的事情
      // 1 清空当前登录的token ，和保存的菜单
      // 2 刷新浏览器
      this.$store.commit('clearToken')
      this.$store.commit('clearMenu')
      location.reload()
    },
  },
}
</script>

<style lang="scss" scoped>
header {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: space-between;
  .l-content {
    display: flex;
    align-items: center;
    .el-button {
      margin-right: 20px;
    }
  }
  .r-content {
    .user {
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
  }
}
</style>
<style lang="scss">
/* 在组件中的 样式需要单独新建一个style 不加scoped */

.el-breadcrumb__item {
  .el-breadcrumb__inner {
    color: #666;
    font-weight: normal;
  }
  &:last-child {
    .el-breadcrumb__inner {
      color: #fff;
    }
  }
}
</style>
